package ComIndirectBehaviour;

import jade.core.behaviours.Behaviour;
import Communication.GraphPheromone;
import Perception.PerceptsBase;
import Perception.Percepts;
import java.util.HashSet;
import java.util.HashSet;
import Communication.NoeudPheromone;
/**
 * TODO description
 */
public class PheromoneBehaviour extends Behaviour {

	private String name;
	private PerceptsBase percepts;
	private HashSet<String> noeuds;
	private HashSet<String>aretes;
	
	public PheromoneBehaviour(String name, PerceptsBase percepts)
	{
		this.name = name;
		this.percepts = percepts;
		noeuds = new HashSet<String>();
		aretes = new HashSet<String>();
	}
	
	public void action()
	{
		GraphPheromone.updatePh(name);
		updateGraph();
	}
	
	public void updateGraph()
	{
		if(percepts.perceptsExists("visibleEdge"))
		{
			for(Percepts p : percepts.getPercepts("visibleEdge"))
			{
				
				String node1 = (String)(p.getParam("node1").getValue());
				String node2 = (String)(p.getParam("node2").getValue());
				
				if(!noeuds.contains(node1))
					GraphPheromone.AddNoeudPheromone(node1);
				if(!noeuds.contains(node2))
					GraphPheromone.AddNoeudPheromone(node2);
				if(!aretes.contains(node1+"-"+node2) && !aretes.contains(node1+"+"+node2))
					GraphPheromone.addAretePheromone(node1, node2);
				
			}
			
		}
	}
	
	public boolean done()
	{
		return false;
	}
}